package com.soundfrequencyapp.actions;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

import com.soundfrequencyapp.R;

public class VideoActivity extends Activity {

	public static final String EXTRA_VIDEO_ID = "videoid";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.screen_activity_play_video);

		Intent i = getIntent();
		
		if (i != null) {
			int videoId = i.getIntExtra(EXTRA_VIDEO_ID, 0);
			VideoView videoView = (VideoView) findViewById(R.id.video_view);
			MediaController mediaController = new MediaController(this);
			mediaController.setAnchorView(videoView);
			videoView.setMediaController(mediaController);
			videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + videoId));
			
			videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
				
				@Override
				public void onCompletion(MediaPlayer mp) {
					VideoActivity.this.finish();
				}
			});
			
			videoView.start();
		}
		
	}
	
}
